package com.jspgou.cms.manager.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jspgou.cms.dao.PromoteDao;
import com.jspgou.cms.entity.Balance;
import com.jspgou.cms.entity.Category;
import com.jspgou.cms.entity.Promote;
import com.jspgou.cms.entity.Store;
import com.jspgou.cms.manager.PromoteMng;
import com.jspgou.common.hibernate3.Updater;
import com.jspgou.common.page.Pagination;
import com.jspgou.core.entity.Website;

@Service
@Transactional
public class PromoteMngImpl implements PromoteMng {
	@Transactional(readOnly = true)
	public Pagination getPage(int pageNo, int pageSize) {
		Pagination page = dao.getPage(pageNo, pageSize);
		return page;
	}
	
	public Pagination getPage(Long websiteId,Long storeId,Boolean disable,Boolean deleted,int pageNo, int pageSize){
	    Pagination page=dao.getPage(websiteId, storeId, disable,deleted, pageNo, pageSize);
	    return page;	
	}
	
	public List<Promote> getList(Long websiteId,Long storeId,Boolean disable,Boolean deleted){
		List<Promote> list=dao.getList(websiteId, storeId, disable, deleted);
		return list;
	}

	@Transactional(readOnly = true)
	public Promote findById(Long id) {
		Promote entity = dao.findById(id);
		return entity;
	}

	public Promote save(Promote bean) {
		dao.save(bean);
		return bean;
	}
	
	public Promote save(Promote bean,Website web,Store store){
		bean.setWebsite(web);
		bean.setStore(store);
		dao.save(bean);
		return bean;
	}

	public Promote update(Promote bean) {
		Updater<Promote> updater = new Updater<Promote>(bean);
		Promote entity = dao.updateByUpdater(updater);
		return entity;
	}

	public Promote deleteById(Long id) {
		Promote bean = dao.deleteById(id);
		return bean;
	}
	
	public Promote[] deleteByIds(Long[] ids) {
		Promote[] beans = new Promote[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	private PromoteDao dao;

	@Autowired
	public void setDao(PromoteDao dao) {
		this.dao = dao;
	}
	
	public boolean checkingProduct(Long id) {
		return dao.checkingProduct(id);
	}
}